package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerProblemBack;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.utils.MyUtils;
import java.util.ArrayList;

public class CustomerProblemBackListAdapter<T> extends BaseAdapter {

  private ArrayList<T> objects = new ArrayList<>();

  private Context context;
  private LayoutInflater layoutInflater;

  public CustomerProblemBackListAdapter(Context context, ArrayList<T> objects) {
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    this.objects = objects;
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      //convertView = layoutInflater.inflate(R.layout.adapter_locale_work_query_count, parent, false);
      convertView = layoutInflater.inflate(R.layout.adapter_customer_back, parent, false);
      convertView.setTag(new ViewHolder(convertView));
    }
    initializeViews(getItem(position), (ViewHolder) convertView.getTag());
    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder) {
    CustomerProblemBack item = (CustomerProblemBack) object;
    holder.ivLogo.setImageResource(R.drawable.ic_feedback);
    if ("S".equalsIgnoreCase(item.getProblemType())) {
      holder.tvTitle.setText(R.string.deviceProblem);
    } else if ("F".equalsIgnoreCase(item.getProblemType())) {
      holder.tvTitle.setText(R.string.serviceProblem);
    } else if ("Z".equalsIgnoreCase(item.getProblemType())) {
      holder.tvTitle.setText(R.string.suggest);
    } else {
      holder.tvTitle.setText("");
    }
    MyUtils.switchShadowStutus(context, holder.tvStatus, item.getDataStatus());
    holder.tvContent.setText(item.getProblemDetails());
    holder.tvBottom.setText(
        MyStringUtil.connect(item.getRegStaffName(), MyStringUtil.SEPEREATE, item.getRegDate()));
  }

  static class ViewHolder {
    @BindView(R.id.iv_logo) ImageView ivLogo;
    @BindView(R.id.tv_title) TextView tvTitle;
    @BindView(R.id.tv_status) TextView tvStatus;
    @BindView(R.id.tv_content) TextView tvContent;
    @BindView(R.id.tv_bottom) TextView tvBottom;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}
